package com.atguigu.guli.service.edu.controller.api;

import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.edu.entity.Teacher;
import com.atguigu.guli.service.edu.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author dyqstart
 * @create 2021-07-02-10:50
 * @since 1.0.0
 */
@Api(tags = "讲师管理")
@RestController
@RequestMapping("/api/edu/teacher")
public class ApiTeacherController {

    @Autowired
    private TeacherService teacherService;

    @ApiOperation("所有讲师列表")
    @GetMapping("list")
    public R listAll(){
        List<Teacher> list = teacherService.list();
        return R.ok().data("items",list).code(2000).message("查询列表成功");
    }

    @ApiOperation(value = "根据ID删除讲师",notes = "根据ID删除讲师")
    //@DeleteMapping("remove/{id}")
    public R removeById(@ApiParam(value = "讲师ID",required = true) @PathVariable String id){
        boolean result = teacherService.removeById(id);
        if (result){
            return R.ok().data("items",1).message("删除讲师成功");
        }else {
            return R.error().data("items",-1).message("删除讲师失败");
        }
    }
}